<template>
	<view class="title-bar">
		<view v-for="(item,index) in titleList" :key="index" class="title-list" :class="current === index?'active':''" @click="changeTitle(index)">
			<view class="title-name">
				{{ item.name }}
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "titleBar",
		props: {
			titleList: {
				type: Array,
				value: []
			},
		},
		data() {
			return {
				current: 0
			}
		},
		created() {
		},
		methods: {
			changeTitle(index) {
				this.current = index;
				this.$emit("getValue", index);
			}
		}
	}
</script>

<style>
	.title-bar {
		width: 100%;
		display: flex;
		align-items: center;
	}

	.title-name {
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: rgba(153, 153, 153, 1);
		line-height: 30rpx;
		padding-bottom: 13rpx;
	}

	.title-list {
		position: relative;
	}

	.title-list:not(:first-child) {
		margin-left: 36rpx;
	}

	.active .title-name {
		font-size: 36rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: rgba(51, 51, 51, 1);
		line-height: 36rpx;
	}

	.active:after {
		content: "";
		display: table;
		width: 40rpx;
		height: 8rpx;
		background: rgba(255, 195, 36, 1);
		border-radius: 4rpx;
		position: absolute;
		left: calc(50% - 20rpx);
		bottom: 0;
	}
</style>
